import java.awt.MouseInfo;
import java.awt.datatransfer.Transferable;

import org.openide.util.datatransfer.ExClipboard;

import com.melloware.jintellitype.JIntellitype;

public class Main
{
	static void exit()
	{
		ClipboardFavorites.save("favorites.ser");
		// Termination, make sure to call before exiting
		JIntellitype.getInstance().cleanUp();
		System.exit(0);
	}

	static float getMousePosX()
	{
		return MouseInfo.getPointerInfo().getLocation().x;
	}

	static float getMousePosY()
	{
		return MouseInfo.getPointerInfo().getLocation().y;
	}

	public static void main(String[] args)
	{
		// display what is currently on the clipboard
		// System.out.println("Clipboard contains:"
		// + textTransfer.getClipboardContents());
		// change the contents and then re-display
		// textTransfer.setClipboardContents("blah, blah, blah");
		// System.out.println("Clipboard contains:"
		// + textTransfer.getClipboardContents());
		
		ExClipboard clipboard = new ExClipboard("pasta") {
			protected ExClipboard.Convertor[] getConvertors() {
				return new ExClipboard.Convertor[] {
					new ExClipboard.Convertor() {
						@Override
						public Transferable convert(Transferable t)
						{
							return t;
						}
					}
				};
			}
		};
		
		TextTransfer textTransfer = new TextTransfer();

		PasteInvoker pasteInvoker = new PasteInvoker();
		
		ClipboardHinstory clipboardHistory = new ClipboardHinstory();
		ClipboardFavorites.load("favorites.ser");
		ClipboardFavorites clipboardFavorites = ClipboardFavorites.getInstance();
		
		TransparentPopupMenu tPopMenu = new TransparentPopupMenu(clipboardFavorites);

		MyClipboardListener mcListener = new MyClipboardListener(textTransfer, clipboardHistory);
		clipboard.addClipboardListener(mcListener);

		MyHotkeyListener hkListener = new MyHotkeyListener(textTransfer,
				pasteInvoker, tPopMenu, clipboardHistory, clipboardFavorites);

		// assign class to be a HotKeyListener
		JIntellitype.getInstance().addHotKeyListener(hkListener);
		
		// assign this class to be a IntellitypeListener
		// JIntellitype.getInstance().addIntellitypeListener(hkListener);

		// MyMouseListener mmListener = new MyMouseListener(tPopMenu);

		while (!hkListener.exitKeyPressed) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			// tPopMenu.setVisible(false);
		}
		
		
		Main.exit();
	}
}
